#pragma once
#include <compl.h>
#include <libapfsds.h>
SECTION("nop") word_t volatile nop_nrs = 0;
SECTION("nop") word_t volatile nop_execution = 0;
SAI NO_UNROLL word_t nop_cb(APFSDS_ARGLIST) {
	PARAM_USED(arg0, arg1, arg2, arg3);
	word_t nops = nop_nrs;
	word_t i = 0;
	do{
		NOP();
		i++;
	}while(i<nops);
	return 0;
}
SAI void nop_cnt_reset(){
	// nop_nrs = 0;
	nop_execution = 0;
}
/* 告诉gcc对这个函数不要循环展开 */
SAI NO_UNROLL word_t nop_cnt_cb(APFSDS_ARGLIST) {
	PARAM_USED(arg0, arg1, arg2, arg3);
	word_t nops = atm_ld(&nop_nrs);
	word_t ret = nop_execution++;
	cmb();
	/* 随机nop避免固定转移模式 */
	nops = hash(ret) & (nops - 1);
	// dbg_printf("%lu\n", nops);
	word_t i = 0;
	do{
		NOP();
	} while(++i < nops);
	
	return ret;
}